package name.wilbur.course.db.bigone.service.impl;

import java.util.List;

import name.wilbur.course.db.bigone.dao.DAOFactory;
import name.wilbur.course.db.bigone.dao.impl.ArticleDAO;
import name.wilbur.course.db.bigone.dao.impl.IArticleDAO;
import name.wilbur.course.db.bigone.model.Article;
import name.wilbur.course.db.bigone.model.BaseDBModel;
import name.wilbur.course.db.bigone.service.IArticleService;

public class ArticleService implements IArticleService {
	private static IArticleDAO articleDAO;
	
	public List<BaseDBModel> getAllArticles() {
		return getArticleDAO().findAll();
	}
	
	public boolean createNewArticle(Article article) {
		return getArticleDAO().create(article);
	}
	
	public boolean deleteArticle(Article article) {
		return getArticleDAO().delete(article.getPk());
	}
	
	public boolean modifyArticle(Article article) {
		return getArticleDAO().update(article);
	}
	
	public static IArticleDAO getArticleDAO() {
		if (articleDAO == null)
			articleDAO = (IArticleDAO) DAOFactory.createDAO(ArticleDAO.class);
		return articleDAO;
	}
}
